<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="jt.classic.system.user.IUser"%>
<%@ page import="jt.classic.system.ISystem"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="org.limp.mine.DateTrimmer"%>
<%
   String context = jt.classic.system.ISystem.getContextPath();
   
   IUser user = ISystem.getSessionUser(request);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>个人密码管理</title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<script>
   function checkit(){
     var rnt = true;
     if(document.form1.pwd.disabled){
        alert("未通过原密码校验，请重新校验原密码");
        rnt = false;
     }else if(isblank(document.form1.pwd)){
        rnt = false;
        alert("请设置新密码");
        document.form1.pwd.focus();
     }else if(trimme(document.form1.pwd) != trimme(document.form1.pwd1) ){
        rnt = false;
        alert("新密码确认失败，请重新输入新密码确认");
        document.form1.pwd1.focus();
     }
     
     return rnt;
   }
   
   function checkmypwd(){
       var pwd = document.form1.orgpwd.value;
   
       Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/system/self.do?method=checkmypwd&pwd=" + pwd,       
		       //提交参数组       
		       fileUpload: true,   
		       form: 'form1',   
		       scope: 'form1',     
		       //成功时回调       
		       success: function(response, options) {       
		           //获取响应的json字符串        
		           Ext.MessageBox.hide();
		           
		           var txt = response.responseText;  
		           
		           if(txt == 1){//校验成功
				        document.form1.orgpwd.disabled = true;
				        document.form1.pwd.disabled = false;
				        document.form1.pwd1.disabled = false;
				        document.getElementById("mypwdok").alt = "原密码正确";
				        document.getElementById("mypwdok").src = context + "/system/user/images/ok.gif";
				        document.getElementById("mypwdok").style.display = "inline";
			       }else{
				        document.form1.orgpwd.value = "";
				        document.getElementById("mypwdok").alt = "原密码错误";
				        document.getElementById("mypwdok").src = context + "/system/user/images/ko.gif";
				        document.getElementById("mypwdok").style.display = "inline";
			       }             
		       }      
	   }); 
   }
   
   function handleReresh(){
      window.location.href = context + "/system/self.do?method=editmypwd";
   }
   
   function handleSubmit(){
        if(checkit()){
            createHidden('opwd', document.form1.orgpwd.value);
        
	        Ext.MessageBox.wait('提交处理过程中...'); 
	   
	   		Ext.Ajax.request({       
			        //请求地址       
			       url: context + "/system/self.do?method=updatemypwd",       
			       //提交参数组       
			       fileUpload: true,   
			       form: 'form1',   
			       scope: 'form1',     
			       //成功时回调       
			       success: function(response, options) {       
			           //获取响应的json字符串        
			           Ext.MessageBox.hide();
			           
			           var json = response.responseText;    
	                   var o = Ext.util.JSON.decode(json);
			           
			           if (o.success) {
						   alert("成功修改个人密码！");
						   handleRefresh();
	                   }else{
			               Ext.Msg.alert('提示', '修改密码失败！'); 
			           }                
			       }      
			     }); 
	     }
   }
</script>
<style>
#lanmu{font-family:Georgia,serif;font-size:12px;
color:#999;}
#lanmu label {font-family:Verdana,sans-serif;
font-weight:bold;color:#660000;	}
#lanmu fieldset{	border:1px solid #cc;padding:0 20px;}
#lanmu legend{font-family:arial,sans-serif;font-weight:bold;
font-size:90%;color:#666;background:#eee;border:1px solid #ccc;
border-bottom-color:#999;border-right-color:#999;padding:4px 8px;}

.button0 {
	font: normal 12px 宋体;
	color: #4c4c4c;
	border-width: 1px;
	height: 25px;
	line-height: 19px;
	cursor: hand;
}
</style>
<!-- app template css -->
<link rel="stylesheet" type="text/css" href="<%=context%>/proframe/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=context%>/app/css/theme4.css" />
<body>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="uid" value="<%=user.id()%>"/> 
<br/>
<div align="center">
<input type="button"  class="button0"  value=" 保 存 " onclick="javascript:handleSubmit();"/>
<input type="button"  class="button0"  value="重新填写" onclick="javascript:handleReresh();"/> 
</div>
<fieldset id="lanmu" style="margin-left:20px;width:80%">
<legend>个人密码管理</legend><br />
  <label>&nbsp;姓名 : </label>
  <b><%=user.iname()%></b>
  <br/><br />
  <label for="orgpwd">&nbsp;原密码 : </label>
  <input id="orgpwd" name="orgpwd" style="width:400px;" class="box3" type="password" id="orgpwd" onblur="javascript:checkmypwd();"/>
    &nbsp;<img id="mypwdok" alt="" src="<%=context%>/system/user/images/ok.gif" style="display:none;">
    <br/><br />
  <label for="pwd">&nbsp;新密码 : </label>
   <input id="pwd" name="pwd" style="width:400px;"  class="box3" disabled type="password" id="pwd" />
  <br/><br />
  <label for="pwd1">&nbsp;新密码确认 : </label>
  <input id="pwd1" name="pwd1" style="width:400px;"  class="box3" disabled type="password" id="pwd1" />
  <br/><br />
</fieldset>
</form>
</body>
</html>
